home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / Airport Radar™ / Source / CAppearanceApp.cp < prev    next >
Encoding:
Text File  |  2001-06-23  |  4.7 KB  |  184 lines

  1. // ===========================================================================
  2. //    CAppearanceApp.cp         ©1994-1999 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //    This file contains the starter code for a basic PowerPlant project
  5.  
  6. #include "CAppearanceApp.h"
  7.  
  8. #include <LGrowZone.h>
  9. #include <PP_Messages.h>
  10. #include <PP_Resources.h>
  11. #include <UDrawingState.h>
  12. #include <UMemoryMgr.h>
  13. #include <URegistrar.h>
  14. #include <UEnvironment.h>
  15.  
  16. #include <UControlRegistry.h>
  17.  
  18. #include <LWindow.h>
  19.  
  20. #include <Appearance.h>
  21. #include "RadarView.h"
  22.  
  23.  
  24.     // Constant declarations
  25. const ResIDT    PPob_SampleWindow            = 128;
  26.  
  27.  
  28. // ===========================================================================
  29. //    • main
  30. // ===========================================================================
  31.  
  32. int main()
  33. {                            
  34.         // Set Debugging options
  35.     SetDebugThrow_(debugAction_Alert);
  36.     SetDebugSignal_(debugAction_Alert);
  37.  
  38.         // Initialize Memory Manager. Parameter is the number of
  39.         // master pointer blocks to allocate
  40.     InitializeHeap(3);
  41.     
  42.         // Initialize standard Toolbox managers
  43.     UQDGlobals::InitializeToolbox(&qd);
  44.     
  45.         // Install a GrowZone to catch low-memory situations    
  46.     new LGrowZone(20000);
  47.  
  48.         // Create the application object and run
  49.     CAppearanceApp    theApp;
  50.     theApp.Run();
  51.     
  52.     return 0;
  53. }
  54.  
  55.  
  56. // ---------------------------------------------------------------------------
  57. //    • CAppearanceApp                                [public]
  58. // ---------------------------------------------------------------------------
  59. //    Application object constructor
  60.  
  61. CAppearanceApp::CAppearanceApp()
  62. {
  63.         // Register ourselves with the Appearance Manager
  64.     if (UEnvironment::HasFeature(env_HasAppearance)) {
  65.         ::RegisterAppearanceClient();
  66.     }
  67.  
  68.     RegisterClasses();
  69. }
  70.  
  71.  
  72. // ---------------------------------------------------------------------------
  73. //    • ~CAppearanceApp                                [public, virtual]
  74. // ---------------------------------------------------------------------------
  75. //    Application object destructor
  76.  
  77. CAppearanceApp::~CAppearanceApp()
  78. {
  79.     // Nothing
  80. }
  81.  
  82.  
  83. // ---------------------------------------------------------------------------
  84. //    • StartUp                                        [protected, virtual]
  85. // ---------------------------------------------------------------------------
  86. //    Perform an action in response to the Open Application AppleEvent.
  87. //    Here, issue the New command to open a window.
  88.  
  89. void
  90. CAppearanceApp::StartUp()
  91. {
  92.     ObeyCommand(cmd_New, nil);
  93. }
  94.  
  95.  
  96. // ---------------------------------------------------------------------------
  97. //    • ObeyCommand                                    [public, virtual]
  98. // ---------------------------------------------------------------------------
  99. //    Respond to Commands. Returns true if the Command was handled, false if not.
  100.  
  101. Boolean
  102. CAppearanceApp::ObeyCommand(
  103.     CommandT    inCommand,
  104.     void*        ioParam)
  105. {
  106.     Boolean        cmdHandled = true;    // Assume we'll handle the command
  107.  
  108.     switch (inCommand) {
  109.  
  110.         case cmd_New: {
  111.             LWindow* theWindow = LWindow::CreateWindow(PPob_SampleWindow, this);
  112.             ThrowIfNil_(theWindow);
  113.  
  114.             theWindow->Show();
  115.             break;
  116.         }
  117.  
  118.         default: {
  119.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  120.             break;
  121.         }
  122.     }
  123.     
  124.     return cmdHandled;
  125. }
  126.  
  127.  
  128. // ---------------------------------------------------------------------------
  129. //    • FindCommandStatus                                [public, virtual]
  130. // ---------------------------------------------------------------------------
  131. //    Determine the status of a Command for the purposes of menu updating.
  132.  
  133. void
  134. CAppearanceApp::FindCommandStatus(
  135.     CommandT    inCommand,
  136.     Boolean&    outEnabled,
  137.     Boolean&    outUsesMark,
  138.     UInt16&        outMark,
  139.     Str255        outName)
  140. {
  141.     switch (inCommand) {
  142.  
  143.         case cmd_New: {
  144.             outEnabled = true;
  145.             break;
  146.         }
  147.  
  148.         default: {
  149.             LApplication::FindCommandStatus(inCommand, outEnabled,
  150.                                             outUsesMark, outMark, outName);
  151.             break;
  152.         }
  153.     }
  154. }
  155.  
  156.  
  157. // ---------------------------------------------------------------------------
  158. //    • RegisterClasses                                [protected]
  159. // ---------------------------------------------------------------------------
  160. //    To reduce clutter within the Application object's constructor, class
  161. //    registrations appear here in this seperate function for ease of use.
  162.  
  163. void
  164. CAppearanceApp::RegisterClasses()
  165. {
  166.         // Register core PowerPlant classes.
  167.     RegisterClass_(LWindow);
  168.     RegisterClass_(RadarView);
  169.  
  170.         // Register the Appearance Manager/GA classes. You may want
  171.         // to remove this use of UControlRegistry and instead perform
  172.         // a "manual" registration of the classes. This cuts down on
  173.         // extra code being linked in and streamlines your app and
  174.         // project. However, use UControlRegistry as a reference/index
  175.         // for your work, and ensure to check UControlRegistry against
  176.         // your registrations each PowerPlant release in case
  177.         // any mappings might have changed.
  178.         
  179.     UControlRegistry::RegisterClasses();
  180. }
  181.  
  182.  
  183.  
  184.